package org.jeecg.modules.flowermater.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.flowermater.entity.*;
import org.jeecg.modules.flowermater.mapper.*;
import org.jeecg.modules.flowermater.service.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description: 采后物资台账表
 * @Author: jeecg-boot
 * @Date: 2022-07-13
 * @Version: V1.0
 */
@Service
@Slf4j
public class FlowerMaterialBookServiceImpl extends ServiceImpl<FlowerMaterialBookMapper, FlowerMaterialBook> implements IFlowerMaterialBookService {


    @Autowired
    private FlowerMaterialInMainMapper flowerMaterialInMainMapper;

    @Autowired
    private FlowerMaterialBookMapper flowerMaterialBookMapper;
    @Autowired
    private FlowerMaterialInMapper flowerMaterialInMapper;

    @Autowired
    private FlowerMaterialOutMainMapper flowerMaterialOutMainMapper;
    @Autowired
    private FlowerMaterialOutMapper flowerMaterialOutMapper;

    @Autowired
    private FlowerMaterialInLogMapper flowerMaterialInLogMapper;

    @Autowired
    private FlowerMaterialOutLogMapper flowerMaterialOutLogMapper;


    private static Object tickets = "material1000";

    /**
     * 新增台账库存
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public synchronized boolean createBooks(FlowerMaterialInMain flowerMaterialInMain, List<FlowerMaterialIn> flowerMaterialInList) {
        boolean res = false;
        String storehouse = flowerMaterialInMain.getStorehouse();
        String inPersonCode = flowerMaterialInMain.getInPersonCode();
        String inPersonName = flowerMaterialInMain.getInPersonName();
        String cost = flowerMaterialInMain.getCost();
        Date inTime = flowerMaterialInMain.getInTime();

        for (FlowerMaterialIn materialIn : flowerMaterialInList) {
            synchronized (tickets) {
                LambdaQueryWrapper<FlowerMaterialBook> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(FlowerMaterialBook::getStorehouse, storehouse);
                queryWrapper.eq(FlowerMaterialBook::getCost, cost);
                queryWrapper.eq(FlowerMaterialBook::getName, materialIn.getName());
                queryWrapper.eq(FlowerMaterialBook::getCode, materialIn.getCode());
                queryWrapper.eq(FlowerMaterialBook::getSpecs, materialIn.getSpecs());
                queryWrapper.eq(FlowerMaterialBook::getModelname, materialIn.getModelname());
                queryWrapper.eq(FlowerMaterialBook::getUnit, materialIn.getUnit());
                queryWrapper.eq(FlowerMaterialBook::getUnitMeasure, materialIn.getUnitMeasure());

                List<FlowerMaterialBook> bookList = flowerMaterialBookMapper.selectList(queryWrapper);
                if (bookList.size() > 1) {
                    throw new RuntimeException("库存台账数据多于一条，请联系管理员");
                } else if (bookList.size() == 1) {
                    FlowerMaterialBook materialBook = bookList.get(0);
                    //更新数量、单价、总价
                    Double num = materialIn.getNum();
                    if (num == null) {
                        num = Double.parseDouble("0");
                    }
                    BigDecimal price = materialIn.getPrice();
                    BigDecimal totalPrice = materialIn.getTotalPrice();
                    if (totalPrice == null) {
                        totalPrice = new BigDecimal("0");
                    }
                    Double numOld = materialBook.getNum();
                    Double totalNumOld = materialBook.getTotalNum();
                    BigDecimal priceOld = materialBook.getPrice();
                    BigDecimal totalPriceOld = materialBook.getTotalPrice();
                    Double numNew = num + numOld;
                    if (numNew.compareTo(Double.parseDouble("0")) < 0) {
                        throw new RuntimeException("库存台账剩余数量不能小于0！");
                    }

                    Double totalNumNew = num + totalNumOld;
                    BigDecimal totalPriceNew = totalPriceOld.add(totalPrice);
                    if (totalPriceNew.compareTo(new BigDecimal("0")) < 0) {
                        throw new RuntimeException("库存台账总价不能小于0！");
                    }

                    BigDecimal priceNew = new BigDecimal(0);
                    if (numNew.compareTo(Double.parseDouble("0")) != 0) {
                        priceNew = totalPriceNew.divide(new BigDecimal(numNew), 2, BigDecimal.ROUND_HALF_UP);
                    }

                    materialBook.setNum(numNew);
                    materialBook.setTotalNum(totalNumNew);
                    materialBook.setPrice(priceNew);
                    materialBook.setTotalPrice(totalPriceNew);
                    flowerMaterialBookMapper.updateById(materialBook);


                    //插入流水日志
                    FlowerMaterialInLog flowerMaterialInLog = new FlowerMaterialInLog();
                    BeanUtils.copyProperties(materialBook,flowerMaterialInLog);
                    flowerMaterialInLog.setId(null);
                    flowerMaterialInLog.setInid(materialIn.getId());
                    flowerMaterialInLog.setInPersonName(inPersonName);
                    flowerMaterialInLog.setInPersonCode(inPersonCode);
                    flowerMaterialInLog.setInTime( inTime );
                    flowerMaterialInLog.setNum( materialIn.getNum() ) ;
                    flowerMaterialInLog.setPrice( materialIn.getPrice() ) ;
                    flowerMaterialInLog.setTotalPrice( materialIn.getTotalPrice() ) ;
                    flowerMaterialInLogMapper.insert(flowerMaterialInLog);


                    res = true;
                } else {
                    FlowerMaterialBook materialBook = new FlowerMaterialBook();
                    //主表
                    materialBook.setStorehouse(storehouse);
                    materialBook.setCost(cost);
                    materialBook.setInPersonCode(inPersonCode);
                    materialBook.setInPersonName(inPersonName);
                    materialBook.setInTime(inTime);
                    //子表
                    materialBook.setInid(materialIn.getId());
                    materialBook.setName(materialIn.getName());
                    materialBook.setCode(materialIn.getCode());
                    materialBook.setSpecs(materialIn.getSpecs());
                    materialBook.setModelname(materialIn.getModelname());
                    if ((materialIn.getNum()).compareTo(Double.parseDouble("0")) < 0) {
                        throw new RuntimeException("库存台账剩余数量不能小于0！");
                    }
                    materialBook.setNum(materialIn.getNum());
                    materialBook.setTotalNum(materialIn.getNum());
                    materialBook.setPrice(materialIn.getPrice());
                    if ((materialIn.getTotalPrice()).compareTo(new BigDecimal("0")) < 0) {
                        throw new RuntimeException("库存台账总价不能小于0！");
                    }
                    materialBook.setTotalPrice(materialIn.getTotalPrice());
                    materialBook.setUnit(materialIn.getUnit());
                    materialBook.setUnitMeasure(materialIn.getUnitMeasure());
                    materialBook.setState(0);//状态 0已入库 1已出库 2删除 3损耗
                    flowerMaterialBookMapper.insert(materialBook);

                    //插入流水日志
                    FlowerMaterialInLog flowerMaterialInLog = new FlowerMaterialInLog();
                    BeanUtils.copyProperties(materialBook,flowerMaterialInLog);
                    flowerMaterialInLog.setId(null);
                    flowerMaterialInLog.setInid(materialIn.getId());
                    flowerMaterialInLog.setInPersonName(inPersonName);
                    flowerMaterialInLog.setInPersonCode(inPersonCode);
                    flowerMaterialInLog.setInTime( inTime );
                    flowerMaterialInLogMapper.insert(flowerMaterialInLog);

                    res = true;
                }
            }
        }
        return res;
    }


    /**
     * 删除台账库存
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBooks(String inMainId) {
        boolean res = false;
        FlowerMaterialInMain flowerMaterialInMain = flowerMaterialInMainMapper.selectById(inMainId);
        List<FlowerMaterialIn> flowerMaterialInList = flowerMaterialInMapper.selectByMainId(inMainId);

        String storehouse = flowerMaterialInMain.getStorehouse();
        String cost = flowerMaterialInMain.getCost();

        List<String> ids = new ArrayList<>();

        for (FlowerMaterialIn materialIn : flowerMaterialInList) {
            ids.add( materialIn.getId());
            synchronized (tickets) {
                LambdaQueryWrapper<FlowerMaterialBook> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(FlowerMaterialBook::getStorehouse, storehouse);
                queryWrapper.eq(FlowerMaterialBook::getCost, cost);
                queryWrapper.eq(FlowerMaterialBook::getName, materialIn.getName());
                queryWrapper.eq(FlowerMaterialBook::getCode, materialIn.getCode());
                queryWrapper.eq(FlowerMaterialBook::getSpecs, materialIn.getSpecs());
                queryWrapper.eq(FlowerMaterialBook::getModelname, materialIn.getModelname());
                queryWrapper.eq(FlowerMaterialBook::getUnit, materialIn.getUnit());
                queryWrapper.eq(FlowerMaterialBook::getUnitMeasure, materialIn.getUnitMeasure());
                List<FlowerMaterialBook> bookList = flowerMaterialBookMapper.selectList(queryWrapper);
                if (bookList.size() > 1) {
                    throw new RuntimeException("库存台账数据多于一条，请联系管理员");
                } else if (bookList.size() == 1) {
                    FlowerMaterialBook materialBook = bookList.get(0);
                    //更新数量、单价、总价
                    Double num = materialIn.getNum();
                    if (num == null) {
                        num = Double.parseDouble("0");
                    }
                    BigDecimal price = materialIn.getPrice();
                    BigDecimal totalPrice = materialIn.getTotalPrice();
                    if (totalPrice == null) {
                        totalPrice = new BigDecimal("0");
                    }
                    Double numOld = materialBook.getNum();
                    Double totalNumOld = materialBook.getTotalNum();
                    BigDecimal priceOld = materialBook.getPrice();
                    BigDecimal totalPriceOld = materialBook.getTotalPrice();
                    Double numNew = numOld - num;
                    if (numNew.compareTo(Double.parseDouble("0")) < 0) {
                        throw new RuntimeException("库存台账剩余数量不能小于0！");
                    }

                    Double totalNumNew = totalNumOld - num;
                    if (numNew < 0 || totalNumNew < 0) {
                        throw new RuntimeException("库存数量小于0，请联系管理员(入库主表inMainId：" + inMainId + ")");
                    }
                    BigDecimal totalPriceNew = totalPriceOld.subtract(totalPrice);
                    if (totalPriceNew.compareTo(new BigDecimal("0")) < 0) {
                        throw new RuntimeException("库存台账总价不能小于0！");
                    }
                    BigDecimal priceNew = new BigDecimal(0);
                    if (numNew.compareTo(Double.parseDouble("0")) != 0) {
                        priceNew = totalPriceNew.divide(new BigDecimal(numNew), 2, BigDecimal.ROUND_HALF_UP);
                    }

                    materialBook.setNum(numNew);
                    materialBook.setTotalNum(totalNumNew);
                    materialBook.setPrice(priceNew);
                    materialBook.setTotalPrice(totalPriceNew);
                    flowerMaterialBookMapper.updateById(materialBook);

                    res = true;
                } else {
                    throw new RuntimeException("未找到相关物资台账：" + storehouse + "|" + materialIn.getName() + "|"
                            + materialIn.getCode() + "|" + materialIn.getModelname() + "|" + materialIn.getSpecs());
                }
            }
        }

        //删除入库流水日志
        QueryWrapper<FlowerMaterialInLog> queryWrapper=new QueryWrapper<>();
        queryWrapper.in("inid" ,ids );
        flowerMaterialInLogMapper.delete( queryWrapper );
        return res;
    }

    /**
     * 返回出库台账---库管取消确认时调用
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public synchronized boolean backOutBooks(String inMainId) {
        boolean res = false;
        FlowerMaterialOutMain flowerMaterialOutMain = flowerMaterialOutMainMapper.selectById(inMainId);
        List<FlowerMaterialOut> flowerMaterialOutList = flowerMaterialOutMapper.selectByMainId(inMainId);

        String storehouse = flowerMaterialOutMain.getStorehouse();
        String inPersonCode = flowerMaterialOutMain.getOutPersonCode();
        String inPersonName = flowerMaterialOutMain.getOutPersonName();
        String cost = flowerMaterialOutMain.getCost();
        Date inTime = flowerMaterialOutMain.getOutTime();
        List<String > ids =new ArrayList<>();
        for (FlowerMaterialOut materialIn : flowerMaterialOutList) {
            ids.add( materialIn.getId() );
            synchronized (tickets) {
                LambdaQueryWrapper<FlowerMaterialBook> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(FlowerMaterialBook::getStorehouse, storehouse);
                queryWrapper.eq(FlowerMaterialBook::getCost, cost);
                queryWrapper.eq(FlowerMaterialBook::getName, materialIn.getName());
                queryWrapper.eq(FlowerMaterialBook::getCode, materialIn.getCode());
                queryWrapper.eq(FlowerMaterialBook::getSpecs, materialIn.getSpecs());
                queryWrapper.eq(FlowerMaterialBook::getModelname, materialIn.getModelname());
                queryWrapper.eq(FlowerMaterialBook::getUnit, materialIn.getUnit());
                queryWrapper.eq(FlowerMaterialBook::getUnitMeasure, materialIn.getUnitMeasure());

                List<FlowerMaterialBook> bookList = flowerMaterialBookMapper.selectList(queryWrapper);
                if (bookList.size() > 1) {
                    throw new RuntimeException("库存台账数据多于一条，请联系管理员");
                } else if (bookList.size() == 1) {
                    FlowerMaterialBook materialBook = bookList.get(0);
                    //更新数量、单价、总价
                    Double num = materialIn.getNum();
                    if (num == null) {
                        num = Double.parseDouble("0");
                    }
                    BigDecimal price = materialIn.getPrice();
                    BigDecimal totalPrice = materialIn.getTotalPrice();
                    if (totalPrice == null) {
                        totalPrice = new BigDecimal("0");
                    }
                    Double numOld = materialBook.getNum();
                    BigDecimal priceOld = materialBook.getPrice();
                    BigDecimal totalPriceOld = materialBook.getTotalPrice();
                    Double numNew = num + numOld;
                    if (numNew.compareTo(Double.parseDouble("0")) < 0) {
                        throw new RuntimeException("库存台账剩余数量不能小于0！");
                    }
                    BigDecimal totalPriceNew = totalPriceOld.add(totalPrice);
                    if (totalPriceNew.compareTo(new BigDecimal("0")) < 0) {
                        throw new RuntimeException("库存台账总价不能小于0！");
                    }
                    BigDecimal priceNew = new BigDecimal(0);
                    if (numNew.compareTo(Double.parseDouble("0")) != 0) {
                        priceNew = totalPriceNew.divide(new BigDecimal(numNew), 2, BigDecimal.ROUND_HALF_UP);
                    }
                    materialBook.setNum(numNew);
                    materialBook.setPrice(priceNew);
                    materialBook.setTotalPrice(totalPriceNew);
                    materialBook.setOutPersonCode(inPersonCode);
                    materialBook.setOutPersonName(inPersonName);
                    materialBook.setOutTime(inTime);
                    flowerMaterialBookMapper.updateById(materialBook);

                    res = true;
                } else {
                    throw new RuntimeException("未找到相关物资台账：" + storehouse + "|" + materialIn.getName() + "|"
                            + materialIn.getCode() + "|" + materialIn.getModelname() + "|" + materialIn.getSpecs());
                }
            }
        }
        //删除入库流水日志
        QueryWrapper<FlowerMaterialOutLog> queryWrapper=new QueryWrapper<>();
        queryWrapper.in("outid" ,ids );
        flowerMaterialOutLogMapper.delete( queryWrapper );
        return res;
    }


    /**
     * 出库的扣减台账库存-----库管确认出库时调用
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean createOutBooks(FlowerMaterialOutMain flowerMaterialOutMain, List<FlowerMaterialOut> flowerMaterialOutList) {
        boolean res = false;
        String storehouse = flowerMaterialOutMain.getStorehouse();
        String cost = flowerMaterialOutMain.getCost();

        for (FlowerMaterialOut materialIn : flowerMaterialOutList) {

            synchronized (tickets) {
                LambdaQueryWrapper<FlowerMaterialBook> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(FlowerMaterialBook::getStorehouse, storehouse);
                queryWrapper.eq(FlowerMaterialBook::getCost, cost);
                queryWrapper.eq(FlowerMaterialBook::getName, materialIn.getName());
                queryWrapper.eq(FlowerMaterialBook::getCode, materialIn.getCode());
                queryWrapper.eq(FlowerMaterialBook::getSpecs, materialIn.getSpecs());
                queryWrapper.eq(FlowerMaterialBook::getModelname, materialIn.getModelname());
                queryWrapper.eq(FlowerMaterialBook::getUnit, materialIn.getUnit());
                queryWrapper.eq(FlowerMaterialBook::getUnitMeasure, materialIn.getUnitMeasure());
                List<FlowerMaterialBook> bookList = flowerMaterialBookMapper.selectList(queryWrapper);
                if (bookList.size() > 1) {
                    throw new RuntimeException("库存台账数据多于一条，请联系管理员");
                } else if (bookList.size() == 1) {
                    FlowerMaterialBook materialBook = bookList.get(0);
                    //更新数量、单价、总价
                    Double num = materialIn.getNum();
                    if (num == null) {
                        num = Double.parseDouble("0");
                    }
                    BigDecimal price = materialIn.getPrice();
                    BigDecimal totalPrice = materialIn.getTotalPrice();
                    if (totalPrice == null) {
                        totalPrice = new BigDecimal("0");
                    }
                    Double numOld = materialBook.getNum();
                    BigDecimal priceOld = materialBook.getPrice();
                    BigDecimal totalPriceOld = materialBook.getTotalPrice();
                    Double numNew = numOld - num;
                    if (numNew < 0) {
                        throw new RuntimeException(materialIn.getName()+materialIn.getCode()+"库存数量不足，请联系管理员(出库单号：" + flowerMaterialOutMain.getNo() + ")");
                    }
                    if (numNew.compareTo(Double.parseDouble("0")) < 0) {
                        throw new RuntimeException(materialIn.getName()+materialIn.getCode()+"库存数量不足！");
                    }
                    BigDecimal totalPriceNew = totalPriceOld.subtract(totalPrice);
                    log.info("原始出库总金额 totalPrice= "+ totalPrice + "---------原始台账剩余总金额--totalPriceOld:"+totalPriceOld + " ----出库子表id:"+materialIn.getId()  );
                    if(numNew==0 || numNew.compareTo(Double.parseDouble("0")) == 0){
                        //最后一笔出库，磨平总价差额
                        //最后一笔出库，磨平总价差额
                        //最后一笔出库，磨平总价差额
                        BigDecimal allTotalPriceIn = flowerMaterialInMainMapper.queryTotalPriceIn(storehouse,cost,materialIn.getName(),materialIn.getCode(),materialIn.getSpecs(),materialIn.getModelname(),materialIn.getUnit(), materialIn.getUnitMeasure());
                        BigDecimal allTotalPriceOut = flowerMaterialOutMainMapper.queryTotalPriceOut(storehouse,cost,materialIn.getName(),materialIn.getCode(),materialIn.getSpecs(),materialIn.getModelname(),materialIn.getUnit(), materialIn.getUnitMeasure(),materialIn.getId());
                        if(allTotalPriceOut==null){
                            allTotalPriceOut=BigDecimal.ZERO ;
                        }
                        log.info("最后一笔出库，磨平总价差额:总入库 = "+allTotalPriceIn + "-----------");
                        log.info("最后一笔出库，磨平总价差额:总出库 = "+allTotalPriceOut + "-----------");
                        BigDecimal lastTotalPrice = allTotalPriceIn.subtract(allTotalPriceOut);
                        log.info("最后一笔出库，磨平总价差额:计算得到最后出库总价 = "+lastTotalPrice + "-----------");
                        if(totalPrice.compareTo(lastTotalPrice)!=0){
                            totalPrice = lastTotalPrice;
                            //同时修改出库子表的总价格
                            FlowerMaterialOut flowerMaterialOut =new FlowerMaterialOut();
                            flowerMaterialOut.setId(materialIn.getId());
                            flowerMaterialOut.setTotalPrice(lastTotalPrice);
                            flowerMaterialOut.setPrice( lastTotalPrice.divide(new BigDecimal(numOld), 2, BigDecimal.ROUND_HALF_UP));
                            flowerMaterialOutMapper.updateById(flowerMaterialOut) ;
                            log.info("最后一笔出库，磨平总价差额:更新了出库单子表的总价 = "+lastTotalPrice + "-----------"+materialIn.getId());
                            totalPriceNew = BigDecimal.ZERO;//强制归0台账剩余金额
                        }
//                        if( totalPriceOld.subtract(totalPrice).compareTo(BigDecimal.ZERO)!=0){
//                            log.error("最后磨平金额出现错误，请联系管理员呢！");
//                            throw new RuntimeException("最后磨平金额出现错误，请联系管理员呢！");
//                        }
                    }

                    log.info("台账剩余金额 = "+ totalPriceNew + "---------------------------------totalPriceOld:"+totalPriceOld + " ----totalPrice:"+totalPrice  );
                    //正常出库------
                    //正常出库------
                    if ((numNew==0 || numNew.compareTo(Double.parseDouble("0")) == 0) && totalPriceNew.compareTo(new BigDecimal("0")) < 0) {
                        throw new RuntimeException("库存台账总价不能小于0！");
                    }
                    BigDecimal priceNew = new BigDecimal(0);
                    if (numNew.compareTo(Double.parseDouble("0")) != 0) {
                        priceNew = totalPriceNew.divide(new BigDecimal(numNew), 2, BigDecimal.ROUND_HALF_UP);
                    }
                    materialBook.setNum(numNew);
                    materialBook.setPrice(priceNew);
                    materialBook.setTotalPrice(totalPriceNew);
                    flowerMaterialBookMapper.updateById(materialBook);

                    //创建出库流水
                    FlowerMaterialOutLog flowerMaterialOutLog = new FlowerMaterialOutLog();
                    BeanUtils.copyProperties(materialBook,flowerMaterialOutLog);
                    flowerMaterialOutLog.setId(null) ;
                    flowerMaterialOutLog.setOutid( materialIn.getId() ) ;
                    flowerMaterialOutLog.setOutPersonCode( flowerMaterialOutMain.getOutPersonCode());
                    flowerMaterialOutLog.setOutPersonName( flowerMaterialOutMain.getOutPersonName());
                    flowerMaterialOutLog.setOutTime( flowerMaterialOutMain.getOutTime() );
                    flowerMaterialOutLog.setNum( materialIn.getNum() );
                    flowerMaterialOutLog.setPrice(  materialIn.getPrice() );
                    flowerMaterialOutLog.setTotalPrice(  materialIn.getTotalPrice() );
                    flowerMaterialOutLogMapper.insert(flowerMaterialOutLog );

                    res = true;
                } else {
                    throw new RuntimeException("未找到相关物资台账：" + storehouse + "|" + materialIn.getName() + "|"
                            + materialIn.getCode() + "|" + materialIn.getModelname() + "|" + materialIn.getSpecs());
                }
            }
        }
        return res;
    }
    /**
     *
     * 物资成本查询
     * @param page
     * @param storehouse
     * @param cost
     * @return
     */
    @Override
    public IPage<FlowerMaterialCost> queryMaterCost(IPage<FlowerMaterialCost> page, String storehouse, String cost, String sDate, String eDate) {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
        String psnId = sysUser.getId();
        IPage<FlowerMaterialCost> flowerMaterialBookIPage = baseMapper.queryMaterCost(page, storehouse, cost, sDate, eDate, psnId);
        return flowerMaterialBookIPage;
    }
}
